package com.aispeech.task.api.data.form;

import com.aispeech.data.pojo.task.Request;
import com.aispeech.enums.EAudioType;
import com.aispeech.enums.ETaskType;
import com.aispeech.task.api.data.enums.Errors;
import com.aispeech.task.api.exceptions.ParamsError;
import com.aispeech.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

@Data
@AllArgsConstructor
public class TaskForm {
    private String productId;
    private String taskId;

    public static TaskForm fromMap(Map<String, String> map) {
        String productId = map.getOrDefault("productId", map.get("app_id"));
        String taskId = map.get("task_id");

        if (StringUtils.isNullOrEmpty(productId)) {
            throw new ParamsError(Errors.ERR_CHECK_PARAM, "missing param: app_id");
        }

        if (StringUtils.isNullOrEmpty(taskId)) {
            throw new ParamsError(Errors.ERR_CHECK_PARAM, "missing param: task_id");
        }

        return new TaskForm(productId, taskId);
    }
}
